/*
 * Created by Christopher King
 * Copyright (C) 2007 Christopher King, All Rights Reserved.
 */

package us.cirion.adventure.engine;

/**
 * A Word is simply a thing known to the Game. It may be a thing, an action, or
 * a person. Words form the building blocks that make up actions and effects.
 * 
 * @author Chris
 */
public abstract class Word
{

	private String text;

	/**
	 * Assigns the text of this word. Simply put, this should say what the word
	 * is. It does not need to be in human-readable format.
	 * 
	 * @param text The content of the word.
	 */
	public void setText(String text)
	{
		this.text = text;
	}

	/**
	 * Retrieves the text of this word. The text can distinguish between two
	 * words of the same type.
	 * 
	 * @return The content of the word.
	 */
	public String getText()
	{
		return text;
	}

	/**
	 * Retrieves the text for this word.
	 * 
	 * @return The content of the word.
	 */
	public String toString()
	{
		return text;
	}

	/**
	 * Retrieves human-readable text for the word. This may be used by the user
	 * interface to display a word to the user.
	 * 
	 * @return Human-readable text for the word.
	 */
	public String getDisplayText()
	{
		return text;
	}

	/**
	 * Indicates whether two Words are equivalent. Words must have the same
	 * class and the same string representation in order to match.
	 * 
	 * @return <code>true</code> if the words are equal, <code>false</code>
	 *         otherwise.
	 */
	public boolean equals(Object o)
	{
		if (o == this)
		{
			return true;
		}
		if (!(o instanceof Word))
		{
			return false;
		}
		// Compare actual classes, since it's possible a Noun and Verb (or other
		// Words) may have the same spelling but different semantics (consider
		// "fly" and "fly".)
		return (getClass().equals(o.getClass()) && ((Word) o).toString()
				.equalsIgnoreCase(toString()));
	}

}
